package ch04;

// 客户端代码
public class Client {
    public static void main(String[] args) {
        // 通过反射创建具体工厂实例
        AbstractFactory factory = createFactory("ConcreteFactoryA");

        // 使用工厂实例创建产品
        Product product = factory.createProduct();
        product.doSomething();
    }

    private static AbstractFactory createFactory(String factoryClassName) {
        try {
            // 使用反射创建具体工厂实例
            Class<?> factoryClass = Class.forName(factoryClassName);
            return (AbstractFactory) factoryClass.getDeclaredConstructor().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
